Using the "Engine" object

We have already mentioned, that the "Engine" object represents the report's slider, which manages report's construction. By using the slider's properties and methods, one can manage the process of arrangement bands on a page. First of all let us attend to theory.

The picture below displays the report's page and properties' names, which return different dimensions.

The page has the "PaperWidth" and "PaperHeight" physical dimensions. These dimensions correspond to page's properties of the same name that are visible in the objects' inspector when selecting a page. So, size of an A4-format page would be 210X297mm.

The "PageWidth" and "PageHeight" parameters define the dimensions of a printable region, which is almost always less than physical dimensions of a page. The size of printable region is defined by the page's fields, which depend on such report page properties as "LeftMargin," "TopMargin," "RightMargin," "BottomMargin." The printable region’s size in pixels is returned by the "Engine.PageWidth" and "Engine.PageHeight" properties.

Finally, the "FreeSpace" parameter defines the height of free space on a page. If there is a "Page Footer" band on the page, its height is taken into account when calculating FreeSpace. This parameter is returned in pixels by the "Engine.FreeSpace function." Note that after displaying the next band, free space reduces on a page, and this is what is considered during calculating FreeSpace.

How do ready report's pages form? The FastReport core produces bands on the page as long as there is enough free space. When there is no free space, the "Page Footer" band is printed (if available) and a new blank page is formed. As it was already said, after displaying the next band, the height of free space descends. Moreover, displaying of a next band begins from the current position, which is defined by coordinates on X-axis and Y-axis. This position returns in the "Engine.CurX" and "Engine.CurY" properties respectively. After printing the next band, the CurY position automatically increases by height value of the printed band. After a new page is formed, the "CurY" position is equal to "0." The "CurX" position is modified when printing multi-channel reports.

The "Engine.CurX" and "Engine.CurY" properties are available not only for reading, but also for recording. That means that bands can be shifted manually by using one of appropriate events. For example, when you have a report looking as shown at the picture,

it can be printed in the following way:

This is a result of the script's work, dedicated to the "OnBeforePrint" band's event:

procedure MasterData1OnBeforePrint(Sender: TfrxComponent);

begin

Engine.CurX := Engine.CurX + 5;

end;

Manipulation with the "CurY" property allows, for example, printing bands in splice:

The corresponding script:

procedure MasterData1OnBeforePrint(Sender: TfrxComponent);

begin

Engine.CurY := Engine.CurY - 15;

end;

The "Engine.NewPage" method allows page breaks in any required place of a report. At the same time, printing continues from a new page. Thus, in our example one can insert a break after printing the second record:

procedure

MasterData1OnAfterPrint(Sender: TfrxComponent);

begin

if <Line> = 2 then

Engine.NewPage;

end;

Note, that now we perform it in the "OnAfterPrint" event (that is to say, after the band is already printed). We want to draw your attention to the fact that the "Line" service variable returns the sequence number of the record.

The "Engine.NewColumn" method breaks a column in multi-columned reports. As soon as there is no column left, this method creates a new page